import { useSelector, useDispatch } from 'react-redux';
import * as store from './reducers/partsSlice';
import React from 'react';
import MyHidden from "./MyHidden";

export default function MyErr(props) {
  const dispatch = useDispatch();
  const show_error = useSelector((state) => state.show_error);
  var errs = useSelector((state) => state.errs);
  // React.useEffect(() => {
  //   setTimeout(()=>{
  //     dispatch(store.partsSlice.actions.SHOW_ERROR(false))
  //   },3000);
  // }, [])
  let div_errs=errs.map((err,key)=>{
    return(<div key={key}>{err.errorCode}{err.errorDesc}{err.validatedURL}<hr /></div>)
  });
  return (
    <MyHidden title="" on_hidden={() => {
      dispatch(store.partsSlice.actions.SHOW_ERROR(false))
    }} hidden={!show_error}>
      {div_errs}
    </MyHidden>
  );
}